<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php 
include("../lib.php");
$link=Conectarse();

$ruta=$_POST["dir"];
$text=$_POST["tex"];

mysql_query("INSERT INTO `galerias` (`nombre`) VALUES ('$text')",$link) or die ("Invalid query");
$res=mysql_query("select id from galerias order by id DESC",$link) or die ("Invalid query");

$row=mysql_fetch_array($res);
$galeria=$row["id"];

/*$galeria = "22";
$ruta ="cumple_flaca";*/

$dir = sprintf("Fotos/%s/",$ruta);


if ($handle = opendir($dir))
{
	while (false !== ($file = readdir($handle))) 
	{ 
		if ($file != "." && $file != ".." && $file != "Thumbs.db") 
		{ 
			
		$foto=sprintf("%s%s",$dir,$file);
		$consulta = sprintf("INSERT INTO fotos (id,galeria,foto) VALUES ('', '%s', '%s');",$galeria,$foto);
		mysql_query($consulta,$link) or die ("Invalid query");	
			
		} 
	}
	closedir($handle); 
}
?>
</body>
</html>
